#include "limbo/details/crc32.h"
#include "test-utils.h"

using namespace limbo;

TEST_CASE("crc", "[details]") {
  SECTION("1 byte") {
    char payload[] = "1";
    auto value = details::crc32((uint8_t *)payload, sizeof(payload) - 1);
    value = details::crc32_finalize(value);
    CHECK(value == 0x83DCEFB7);
  }

  SECTION("2 bytes") {
    char payload[] = "19";
    auto value = details::crc32((uint8_t *)payload, sizeof(payload) - 1);
    value = details::crc32_finalize(value);
    CHECK(value == 0xD8819D45);
  }

  SECTION("net sample") {
    uint8_t payload[] = {
        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x48, 0xba, 0x4e, 0x51, 0x39, 0xbb,
        0x08, 0x06, 0x00, 0x01, 0x08, 0x00, 0x06, 0x04, 0x00, 0x01, 0x48, 0xba,
        0x4e, 0x51, 0x39, 0xbb, 0xc0, 0xa8, 0x65, 0x01, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0xc0, 0xa8, 0x65, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    };
    auto value = details::crc32(payload, sizeof(payload));
    value = details::crc32_finalize(value);
    CHECK(value == 0x02394A00);
  }
}
